// 企业文化动画
function initCulture() {
    // 检查是否存在企业文化相关元素
    const cultureSection = document.querySelector('.culture-section');
    if (!cultureSection) {
        console.log('Culture section not found, skipping animation initialization');
        return;
    }

    console.log('Culture animation initialized');

    const cultureCards = document.querySelectorAll('.culture-card');
    const keywords = document.querySelectorAll('.culture-keywords span');

    // 初始化动画
    function initAnimations() {
        // 设置初始状态
        cultureCards.forEach(card => {
            card.style.opacity = '0';
            card.style.transform = 'translateY(20px)';
        });

        keywords.forEach(keyword => {
            keyword.style.opacity = '0';
            keyword.style.transform = 'scale(0.8)';
        });
    }

    // 执行动画
    function animateElements() {
        // 企业文化卡片动画
        cultureCards.forEach((card, index) => {
            setTimeout(() => {
                card.style.transition = 'all 0.6s ease-out';
                card.style.opacity = '1';
                card.style.transform = 'translateY(0)';
            }, index * 200); // 每个卡片延迟200ms
        });

        // 关键词动画
        keywords.forEach((keyword, index) => {
            setTimeout(() => {
                keyword.style.transition = 'all 0.4s ease-out';
                keyword.style.opacity = '1';
                keyword.style.transform = 'scale(1)';
            }, index * 150); // 每个关键词延迟150ms
        });
    }

    // 检查元素是否在视口中
    function isInViewport(element) {
        const rect = element.getBoundingClientRect();
        return (
            rect.top <= (window.innerHeight || document.documentElement.clientHeight) &&
            rect.bottom >= 0
        );
    }

    // 监听滚动事件
    function handleScroll() {
        if (isInViewport(cultureSection)) {
            animateElements();
            window.removeEventListener('scroll', handleScroll);
        }
    }

    // 初始化
    initAnimations();
    window.addEventListener('scroll', handleScroll);
    // 立即检查一次，以防元素已经在视口中
    handleScroll();
}

// 确保在组件加载完成后执行
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initCulture);
} else {
    initCulture();
} 